using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ERPBackend.Models
{
    public class InventoryTransaction : BaseModel
    {
        [Required]
        [StringLength(50)]
        public string TransactionCode { get; set; } = string.Empty;

        [Required]
        public byte TransactionType { get; set; } // 0:采购入库, 1:生产入库, 2:销售出库, 3:其他出库

        [Required]
        public DateTime TransactionDate { get; set; }

        [Required]
        public int MaterialId { get; set; }

        [Required]
        public int WarehouseId { get; set; }

        [StringLength(50)]
        public string? BatchNumber { get; set; }

        [Required]
        [Column(TypeName = "decimal(18,4)")]
        public decimal TransactionQuantity { get; set; } // 正数表示增加，负数表示减少

        [Required]
        [Column(TypeName = "decimal(18,4)")]
        public decimal BeforeStock { get; set; }

        [Required]
        [Column(TypeName = "decimal(18,4)")]
        public decimal AfterStock { get; set; }

        [Required]
        public int OperatorId { get; set; }

        [StringLength(500)]
        public string? Remark { get; set; }

        // 导航属性
        [ForeignKey("MaterialId")]
        public Material? Material { get; set; }

        [ForeignKey("WarehouseId")]
        public Warehouse? Warehouse { get; set; }

        [ForeignKey("OperatorId")]
        public User? Operator { get; set; }
    }
}